<?php

require_once '../lib/database.php';

class photo extends table{

  const TABLE_NAME              = "t_photos";
  const PRIMARY_KEY             = "photo_id";
  
  var $photo_id;         
  var $match_id;        
  var $photo_name;   
  var $photo_isVisible;     
  var $photo_isSpecial;   
  var $photo_order;     
    
  /**
   *
   * @param type $array
   * @return saison
   */
  
  public function __construct($array) {
    parent::__construct($array);
    return $this;
  }
  
  public static function getMatchPhoto($match_id){
    $match = match::getMatch($match_id);
  }
  
  public static function hasMatchPhoto($match_id,$inDb=true,$onDisk=true,$hasSpecial=false){
    $db = self::getDb();
    
    $sql = sprintf("select count(*) from %s where match_id=%d",self::getTableName(),$match_id);
    
    $where=array();
    
    if($hasSpecial){
      $where[]="photo_isSpecial=1";
    }
    
    if(count($where)){
      $sql = sprintf("%s where %s",$sql,join(' AND ',$where));
    }
    
    $cnt = $db->Count($sql);
    
    if($cnt==0 && $onDisk==true){
      
    }
    
  }
  
  public static function getMatchPhotos($match_id){
    
    $db = self::getDb(); /* @var $db */
     
    $sql=sprintf("select * from %s where match_id=%d order by photo_order,photo_name",self::getTableName(),$match_id);
    
  }

}

